package cn.zktr.Personnel.model.service.zhouyongcong.end;

import java.util.Calendar;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.zktr.Personnel.common.TimeStamp;
import cn.zktr.Personnel.model.pojos.PerPmsEmp;
import cn.zktr.Personnel.model.pojos.PerPmsPot;
import cn.zktr.Personnel.model.pojos.PerRetRcd;
import cn.zktr.Personnel.model.pojos.PerRetRse;
import cn.zktr.Personnel.model.service.zhouyongcong.boolService;
import cn.zktr.Personnel.model.service.zhouyongcong.saveAuditService;
import cn.zktr.Personnel.model.service.zhouyongcong.savePojosService;
import cn.zktr.Personnel.model.service.zhouyongcong.saveService;

@Service
@Transactional(rollbackFor=Exception.class)
public class loginService {
	
	@Autowired
	private saveAuditService sas;
	@Autowired
	private saveService ss;
	@Autowired
	private savePojosService sps;
	@Autowired
	private boolService bs;
	
	public static int getAgeByIdCard(String c) {
        int iAge = 0;
        Calendar cal = Calendar.getInstance();
        String year = c.substring(6, 10);
        int iCurrYear = cal.get(Calendar.YEAR);
        iAge = iCurrYear - Integer.valueOf(year);
        return iAge;
    }
	public static String getBirthByIdCard(String c) {
		char[] ca = c.substring(6, 14).toCharArray();
        return ca[0]+ca[1]+ca[2]+ca[3]+"-"+ca[4]+ca[5]+"-"+ca[6]+ca[7];
    }
	
	public void emp_login_ru(PerRetRcd prr) {
		PerRetRse prrs = prr.getPerRetRse();
		PerPmsEmp ppe = sas.save_emp(prrs.getRsename(), prrs.getRsecard());
		sps.modif_Emp(ppe);
		PerPmsPot ppp =  prrs.getPerPmsPot();
		ss.save_Stm(ppe.getEmpid(),ppp.getPotid(),ppp.getPerPmsStms().get(0).getPerPmsDept().getDeptid());
		ss.save_Act(ppe.getEmpid());
		ss.save_Empdet(prrs.getPerPmsSex(), ppe.getEmpid(),getAgeByIdCard(prrs.getRsecard()),prrs.getRsemz(),prrs.getRsegj(), new TimeStamp().valueOf(getBirthByIdCard(prrs.getRsecard())), prrs.getRsedizhi());
		ss.save_Emplx(bs.bool_Emplx(), ppe.getEmpid(), 3, prrs.getRsephome());
		ss.save_Emplx(bs.bool_Emplx(), ppe.getEmpid(), 2, prrs.getRseemail());
		ss.save_Zt(ppe.getEmpid(), prrs.getRsehide());
	}
	
	
	
	
}
